require 'recon/content'
require 'test/unit'

require 'xmlrpc/datetime'

class TC_content < Test::Unit::TestCase
  
  def setup
    @c = Content.new
  end

  def test_can_create_content
    assert Content.new
  end
  
  # test accessor methods

  #The title of the item.
  def test_content_has_title
    @c.title = 'titolo'
    assert_equal 'titolo', @c.title
  end
  
  # The URL of the item. 
  def test_content_has_link
    assert c = Content.new
    @c.link = 'http://foo.com/titolo'
    assert_equal 'http://foo.com/titolo', @c.link
  end

  # The item synopsis. 
  def test_content_has_description
    c = Content.new
    @c.description = "bla bla bla bla"
    assert_equal "bla bla bla bla", @c.description
  end
  
  # Email address of the author of the item.
  def test_content_has_author
    c = Content.new
    @c.author = 'author@foo.com'
    assert_equal 'author@foo.com', @c.author
  end

  def test_content_has_category
    c = Content.new
    @c.category = "news", 'www'
    assert_equal ["news", 'www'], @c.category
  end

  # A string that uniquely identifies the item. 
  def test_content_has_guid
    c = Content.new
    @c.guid = "http://foo.com/name;uniquenum"
    assert_equal 'http://foo.com/name;uniquenum', @c.guid
  end

  # publishing time
  def test_content_has_pubdate
    t = Time.now
    assert_equal XMLRPC::DateTime.new(t.year,t.month,t.day,t.hour,t.min,t.sec), @c.pubDate

#    c2= Content.new
#    c2.pubDate= t
#    assert_equal c2.pubDate, c.pubDate
#
#    assert_raises(ArgumentError){ c.pubDate = nil }
  end
  
  # create a hash
  def test_content_to_hash
    t = Time.now
    @c.description = "blablablabla BLA"
    @c.title = "zumzum"
    assert_equal @c.to_hash, {"description" => "blablablabla BLA", "title" => "zumzum", "pubDate" => XMLRPC::DateTime.new(t.year,t.month,t.day,t.hour,t.min,t.sec) }
  end
  
#  def test_hash_without_title
#    c = Content.new
#    c.description = "blablablabla BLA"
#    assert_raise(ArgumentError){ c.to_hash }
#  end
end
